# -*- coding:utf-8 -*-
from utils.db_utils import DbConn
import datetime
from utils.serialization import Serialization
from app.task.common.task_sql import TaskManageSql


class TaskEditDB(object):
    def __init__(self):
        self.serialization = Serialization()
        
    def del_task(self, body):
        """删除任务"""
        params = ["id"]
        null_params = []
        sql = TaskManageSql.DEL_TASK
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def del_task_member(self, body):
        """删除任务团队"""
        params = ["id"]
        null_params = []
        sql = TaskManageSql.TASK_GROUP_DEL_USER
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def edit_task(self, body):
        """编辑任务"""
        params = ["leader","start_date","end_date","plane_time","status","process","id"]
        null_params = []
        sql = TaskManageSql.EDIT_TASK
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def edit_task_member(self, body):
        """编辑任务团队"""
        params = ["task_id","remarks"]
        null_params = ["task_id"]
        sql = TaskManageSql.EDIT_TASK_GROUP
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def add_task(self, body):
        """添加任务"""
        params = ["object_id", "leader", "content", "start_date", "end_date", "plane_time", "status"]
        null_params = ["plane_time","end_date"]
        sql = TaskManageSql.ADD_TASK
        ret = self.serialization.query_info(body, params, null_params, sql)
        return ret
    
    def task_over(self,body):
        """完成任务"""
        params = ["leader", "start_date", "end_date", "plane_time", "status", "id","id"]
        null_params = []
        sql = TaskManageSql.OVER_TASK
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def add_task_member(self, body):
        """添加任务团队"""
        params = ["task_id","remarks","session_user_id","project_id"]
        null_params = []
        sql = TaskManageSql.ADD_TASK_GROUP
        ret = self.serialization.query_info(body, params, null_params, sql)
        return ret
    
    def task_member_add_user(self,body):
        """任务团队人员编辑"""
        params = ["task_id","remarks","session_user_id","project_id"]
        null_params = []
        sql = TaskManageSql.ADD_TASK_GROUP
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def task_member_edit_user(self,body):
        """任务团队人员编辑"""
        params = ["task_id","remarks","session_user_id","project_id","id"]
        null_params = []
        sql = TaskManageSql.TASK_GROUP_EDIT_USER
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def task_member_del_user(self,body):
        """任务团队人员删除"""
        params = ["user_id","task_id"]
        null_params = []
        sql = TaskManageSql.TASK_GROUP_DEL_USER
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
    
    def task_edit_leader(self,body):
        params = ["user_id","task_id"]
        null_params = []
        sql = TaskManageSql.TASK_EDIT_LEADER
        ret = self.serialization.commoit(body, params, null_params, sql)
        return ret
